package graphic;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import klient.Klient;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;

/**
 *  
 * @author Marcin & Bartek
 * 
 * @description Contains Textures
 */
public final class TextureBase {
    private TextureBase(){}
    private static Map<String,Texture> base = new HashMap<>();
    public static int nextID=0;
    public static Texture NO_TEX = get("images/notex.png");
    public static Texture get(String file){
        if(base.containsKey(file)){
            Klient.log("Użyto "+file);
            return base.get(file);
        }else{
            String ext="";
            ext=file.split("\\.")[1];
            ext=ext.toUpperCase();
            try {
                Texture txt = TextureLoader.getTexture(ext, new FileInputStream(new File(file)),true);
                
                base.put(file, txt);
                nextID = txt.getTextureID()+1;
                Klient.log("Załadowano "+file);
                return txt;
            } catch (FileNotFoundException ex) {
                Klient.log("Nie znaleziono pliku "+file);
            } catch (IOException ex) {
                Klient.log("Błąd odczytu "+file);
            }
        }
        return null;
    }    
    public static int getTexID(){
        return nextID++;
    }
}
